<template>
    <div class="boxs">
        <el-tabs v-model="type" type="card" @tab-click="handleClick">
            <el-tab-pane label="三天" name="1"></el-tab-pane>
            <el-tab-pane label="一周" name="2"></el-tab-pane>
            <el-tab-pane label="两周" name="3"></el-tab-pane>
            <el-tab-pane label="一个月" name="4"></el-tab-pane>
            <el-tab-pane label="所有" name="5"></el-tab-pane>
        </el-tabs>

        <el-row :gutter="20">
            <el-col :span="12">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>universal</span>
                        <span style="margin-left: 20px;font-size: 14px;color:red;font-weight: bold;">
                            已退:≈${{usd1}}</span>
                        <el-button style="float: right; " size="mini" type="primary"
                            @click="goList('com.seamobitech.UniversalTVRemoteControl')">查看列表</el-button>
                    </div>
                    <div style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
                        <div class="police-count1" ref="chart1"></div>
                    </div>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>roku</span>
                        <span style="margin-left: 20px;font-size: 14px;color:red;font-weight: bold;">
                            已退:≈${{ usd2 }}</span>
                        <el-button style="float: right; " size="mini" type="primary"
                            @click="goList('com.seamobitech.roku')">查看列表</el-button>
                    </div>
                    <div style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
                        <div class="police-count2" ref="chart2"></div>
                    </div>
                </el-card>
            </el-col>
        </el-row>



        <el-row :gutter="20">
            <el-col :span="12">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>waai</span>
                        <span style="margin-left: 20px;font-size: 14px;color:red;font-weight: bold;">
                            已退:≈${{ usd3 }}</span>
                        <el-button style="float: right; " size="mini" type="primary"
                            @click="goList('com.seamobitech.whatsscanwebclone')">查看列表</el-button>
                    </div>
                    <div style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
                        <div class="police-count3" ref="chart3"></div>
                    </div>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>beautyAi</span>
                        <span style="margin-left: 20px;font-size: 14px;color:red;font-weight: bold;">
                            已退:≈${{ usd4 }}</span>
                        <el-button style="float: right; " size="mini" type="primary"
                            @click="goList('com.seamobitech.QRCodeReadAndGenerate')">查看列表</el-button>
                    </div>
                    <div style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
                        <div class="police-count4" ref="chart4"></div>
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>iosHeartPulse</span>
                        <span style="margin-left: 20px;font-size: 14px;color:red;font-weight: bold;">
                            已退:≈${{ usd5 }}</span>
                        <el-button style="float: right; " size="mini" type="primary"
                            @click="goList('com.seamobitech.BeautyAI')">查看列表</el-button>
                    </div>
                    <div style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
                        <div class="police-count5" ref="chart5"></div>
                    </div>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>momo</span>
                        <span style="margin-left: 20px;font-size: 14px;color:red;font-weight: bold;">
                            已退:≈${{ usd6 }}</span>
                        <el-button style="float: right; " size="mini" type="primary"
                            @click="goList('com.seamobitech.HeartPulse')">查看列表</el-button>
                    </div>
                    <div style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
                        <div class="police-count6" ref="chart6"></div>
                    </div>
                </el-card>
            </el-col>
        </el-row>

    </div>

</template>
<script>

import { getFaceTokens, getTokens } from "@/api/beauty";
import { getList, getCountryList, getLanguageList } from "@/api/iptv";
import { getRefundByPkDay } from "@/api/refund";
import pk from "@/utils/pk";
import * as XLSX from "xlsx";
export default {
    name: "subscription",
    data() {
        return {
            currentList: [],
            countryList: [],
            languageContent: '',
            goalLanguage: "zh_CN",
            languageList: [],
            translateLoading: false,
            pkList: [],

            queryParams: {
                dateRange: {
                    start: '',
                    end: ''
                },
                country: '',
                language: '',
            },
            total: 0,
            loading: false,
            addLoading: false,
            moreArr: [],
            dialogVisible: false,
            form: {
                comment_type: "",
            },
            search: "",
            rules: {
                comment_type: [
                    { required: true, message: "请输入类型", trigger: "blur" },
                ],
            },
            value1: "",
            chartContainer1: null,
            option1: {},
            chartData: [],
            chartContainer2: null,
            option2: {},
            chartData2: [],
            chartContainer3: null,
            option3: {},
            chartData3: [],
            chartContainer4: null,
            option4: {},
            chartData4: [],
            chartContainer5: null,
            option5: {},
            chartData5: [],
            chartContainer6: null,
            option6: {},
            chartData6: [],
            chartContainer7: null,
            option7: {},
            chartData7: [],
            chartContainer8: null,
            option8: {},
            chartData8: [],
            chartContainer9: null,
            option9: {},
            chartData9: [],
            chartContainer10: null,
            option10: {},
            chartData10: [],
            isLoading1: true,
            chart1: null,
            chart2: null,
            chart3: null,
            chart4: null,
            chart5: null,
            chart6: null,
            chart7: null,
            chart8: null,
            chart9: null,
            chart10: null,

            loadingOption: {
                text: '',
                color: '#409eff',
                maskColor: 'rgba(255, 255, 255, 0.8)',
                zlevel: 0
            },
            pk: '',
            pickerOptions: {

            },
            invalidDateRange: false,
            str: '近30天',
            conversionRateMean: 0,
            type: '1',
            pkList: [
                'com.seamobitech.UniversalTVRemoteControl',
                'com.seamobitech.roku',
                'com.seamobitech.whatsscanwebclone',
                // 'com.seamobitech.QRCodeReadAndGenerate',
                'com.seamobitech.BeautyAI',
                'com.seamobitech.HeartPulse',
                'com.trans.translationAiAndSubtitle',
            ],
            parseData1:[],
            parseData2:[],
            parseData3:[],
            parseData4:[],
            parseData5: [],
            parseData6: [],
            usd1:0,
            usd2:0,
            usd3:0,
            usd4:0,
            usd5:0,
            usd6:0,
        };
    },
    created() {

    },

    mounted() {
        this.loadChartsSequentially();

    },
    methods: {
        handleClick(tab, event) {
            this.loadChartsSequentially();
        },
        async loadChartsSequentially() {
            for (let i = 0; i < this.pkList.length; i++) {
                await this.getStatistics(this.pkList[i], i + 1);
            }
        },
        async getLanguageList() {
            const { data } = await getLanguageList()
            this.languageList = data
        },
        async getCountryList() {
            const { data } = await getCountryList()
            this.countryList = data
        },
        goList(pk) {

            this.$router.push({
                path: "/refund/list",
                query: { pk: pk }
            });
        },
        formatDate(date) {
            const options = { year: 'numeric', month: '2-digit', day: '2-digit' };
            return new Date(date).toLocaleDateString('zh-CN', options);
        },
        async getStatistics(pk, chartIndex) {
             
            
            let query = {
                pk: pk,
                type: this.type
            };
            const chartRef = this.$refs[`chart${chartIndex}`]; // 动态选择图表引用
            const chart = this.$echarts.init(chartRef);
            chart.showLoading(this.loadingOption);

            const { data1, data2, totalUSD } = await getRefundByPkDay(query);
            if (data2.length > 0) {
                data2.forEach(x => {
                    x.price = x.price.toFixed(2)
                })
            }
            if (chartIndex == 1) {
                this.parseData1 = data2
                this.usd1 = totalUSD
            }
            if (chartIndex == 2) {
                this.parseData2 = data2
                this.usd2 = totalUSD

            }
            if (chartIndex == 3) {
                this.parseData3 = data2
                this.usd3 = totalUSD

            }
            if (chartIndex == 4) {
                this.parseData4 = data2
                this.usd4 = totalUSD

            }
            if (chartIndex == 5) {
                this.parseData5 = data2
                this.usd5 = totalUSD

            }
            if (chartIndex == 6) {
                this.parseData5 = data2
                this.usd6 = totalUSD

            }
            const counts = { 1: 0, 2: 0 }; // 初始化拒绝和同意的计数
            // 遍历数据并统计 is_agree 的值
            data1.forEach(item => {
                const isAgree = item.is_agree;
                if (isAgree == 1 || isAgree == 2) {
                    counts[isAgree] = (counts[isAgree] || 0) + 1;
                }
            });

            // 准备图表数据
            const chartData = [
                { name: '拒绝', value: counts[1], itemStyle: { color: '#226AFF' } },   
                { name: '同意', value: counts[2], itemStyle: { color: '#FCB746' } }  
            ];

            if (chartData.length > 0) {
                


                const option = {
                    tooltip: {
                        trigger: 'item',
                        formatter: '{b}: {c} ({d}%)'  
                    },
                    legend: { bottom: '10%' },
                    series: [
                        {
                            name: '拒绝/同意',
                            type: 'pie',
                            radius: '42%',
                            data: chartData.map((item, index) => {
                                return {
                                    ...item,
                                    selected: index == 1
                                };
                            }),
                            label: {
                                show: true,
                                formatter: '{b}: {c} ({d}%)'  // 在图中显示名字和值，若添加百分之比，可以用 {b}: {c} ({d}%)
                            },
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

                // 延迟设置选项以查看加载动画
                // setTimeout(() => {
                chart.setOption(option);
                chart.hideLoading();

                //  },100)
                chartRef.style.display = 'block'; // 显示图表
            } else {
                chartRef.style.display = 'none'; // 隐藏无数据的图表
            }
        },

        async getStatistics2() {

            if (!this.queryParams.dateRange.start) {
                // 获取当前时间
                const now = new Date();

                // 获取今天的日期：格式为 YYYY-MM-DD
                const today = now.toISOString().split('T')[0];

                // 获取上一个月的日期
                const prevMonthDate = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
                const startDate = prevMonthDate.toISOString().split('T')[0]; // 开始日期
                // 赋值日期
                this.queryParams = {
                    dateRange: {
                        start: startDate,  // 得到的开始日期
                        end: today,        // 结束日期即今天
                    },
                };

            }
            let query = {
                dateRange: this.queryParams.dateRange,
                type: 'makeup'
            }

            this.chart2 = this.$echarts.init(this.$refs.chart2);
            // 显示加载动画
            this.chart2.showLoading(this.loadingOption);
            let { data } = await getFaceTokens(query);
            this.chartData = data;

            // 提取日期和计数数据
            const dates = data.map(item => item.date);
            const counts = data.map(item => item.total_tokens);
            const prompt_tokens = data.map(item => item.prompt_tokens);
            const completion_tokens = data.map(item => item.completion_tokens);
            this.option2 = {
                color: ['#3489FF'],
                grid: {
                    left: '5.5%',
                    right: '0%'
                },
                xAxis: [{
                    type: 'category',
                    data: dates, // 设置 x 轴数据
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        fontSize: 13,
                        color: '#999999',
                        margin: 13
                    },
                    splitLine: {
                        lineStyle: {
                            show: true,
                            color: '#DDDDDD'
                        }
                    }
                }],
                yAxis: [{
                    type: 'value',
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        fontSize: 13,
                        color: '#999999',
                        margin: 13
                    },
                    splitLine: {
                        lineStyle: {
                            show: true,
                            color: '#DDDDDD'
                        }
                    }
                }],
                series: [{
                    data: counts, // 设置 y 轴数据
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [{
                                offset: 0,
                                color: '#94cdfc' // 0% 处的颜色
                            }, {
                                offset: 1,
                                color: '#F4F7FF' // 100% 处的颜色
                            }]
                            // global: false // 缺省为 false
                        }
                    },
                    label: {
                        show: true,
                        position: 'top',
                    }
                }],
                tooltip: { // 鼠标悬浮提示框显示 X和Y 轴数据
                    trigger: 'axis',
                    backgroundColor: 'rgba(32, 33, 36,.7)',
                    borderColor: 'rgba(32, 33, 36,0.20)',
                    borderWidth: 1,
                    textStyle: { // 文字提示样式
                        color: '#fff',
                        fontSize: '12'
                    },
                    axisPointer: { // 坐标轴虚线
                        type: 'cross',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    },
                    formatter: function (params) {
                        const index = params[0].dataIndex;
                        return `
                                日期: ${dates[index]}<br/>
                                发-消耗: ${prompt_tokens[index]}<br/>
                                收-消耗: ${completion_tokens[index]}<br/>
                                总消耗: ${counts[index]}
                            `;
                    }
                },
                dataZoom: {
                    type: 'inside'
                }
            };
            setTimeout(() => {
                this.initChart2();
                this.chart2.hideLoading();

            })
        },
        async getStatistics3() {

            if (!this.queryParams.dateRange.start) {
                // 获取当前时间
                const now = new Date();

                // 获取今天的日期：格式为 YYYY-MM-DD
                const today = now.toISOString().split('T')[0];

                // 获取上一个月的日期
                const prevMonthDate = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
                const startDate = prevMonthDate.toISOString().split('T')[0]; // 开始日期
                // 赋值日期
                this.queryParams = {
                    dateRange: {
                        start: startDate,  // 得到的开始日期
                        end: today,        // 结束日期即今天
                    }
                };

            }
            let query = {
                dateRange: this.queryParams.dateRange,
                type: 'product'
            }

            this.chart3 = this.$echarts.init(this.$refs.chart3);
            // 显示加载动画
            this.chart3.showLoading(this.loadingOption);
            let { data } = await getFaceTokens(query);
            this.chartData = data;

            // 提取日期和计数数据
            const dates = data.map(item => item.date);
            const counts = data.map(item => item.total_tokens);
            const prompt_tokens = data.map(item => item.prompt_tokens);
            const completion_tokens = data.map(item => item.completion_tokens);

            this.option3 = {
                color: ['#3489FF'],
                grid: {
                    left: '5.5%',
                    right: '0%'
                },
                xAxis: [{
                    type: 'category',
                    data: dates, // 设置 x 轴数据
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        fontSize: 13,
                        color: '#999999',
                        margin: 13
                    },
                    splitLine: {
                        lineStyle: {
                            show: true,
                            color: '#DDDDDD'
                        }
                    }
                }],
                yAxis: [{
                    type: 'value',
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        fontSize: 13,
                        color: '#999999',
                        margin: 13
                    },
                    splitLine: {
                        lineStyle: {
                            show: true,
                            color: '#DDDDDD'
                        }
                    }
                }],
                series: [{
                    data: counts, // 设置 y 轴数据
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [{
                                offset: 0,
                                color: '#94cdfc' // 0% 处的颜色
                            }, {
                                offset: 1,
                                color: '#F4F7FF' // 100% 处的颜色
                            }]
                            // global: false // 缺省为 false
                        }
                    },
                    label: {
                        show: true,
                        position: 'top',
                    }
                }],
                tooltip: { // 鼠标悬浮提示框显示 X和Y 轴数据
                    trigger: 'axis',
                    backgroundColor: 'rgba(32, 33, 36,.7)',
                    borderColor: 'rgba(32, 33, 36,0.20)',
                    borderWidth: 1,
                    textStyle: { // 文字提示样式
                        color: '#fff',
                        fontSize: '12'
                    },
                    axisPointer: { // 坐标轴虚线
                        type: 'cross',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    },
                    formatter: function (params) {
                        const index = params[0].dataIndex;
                        return `
                                日期: ${dates[index]}<br/>
                                发-消耗: ${prompt_tokens[index]}<br/>
                                收-消耗: ${completion_tokens[index]}<br/>
                                总消耗: ${counts[index]}
                            `;
                    }
                },
                dataZoom: {
                    type: 'inside'
                }
            };
            setTimeout(() => {
                this.initChart3();
                this.chart3.hideLoading();

            })
        },
        async getStatistics4() {
            if (!this.queryParams.dateRange.start) {
                // 获取当前时间
                const now = new Date();

                // 获取今天的日期：格式为 YYYY-MM-DD
                const today = now.toISOString().split('T')[0];

                // 获取上一个月的日期
                const prevMonthDate = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
                const startDate = prevMonthDate.toISOString().split('T')[0]; // 开始日期
                // 赋值日期
                this.queryParams = {
                    dateRange: {
                        start: startDate,  // 得到的开始日期
                        end: today,        // 结束日期即今天
                    },

                };

            }
            let query = {
                dateRange: this.queryParams.dateRange,
            }

            this.chart4 = this.$echarts.init(this.$refs.chart4);
            // 显示加载动画
            this.chart4.showLoading(this.loadingOption);
            this.chart5 = this.$echarts.init(this.$refs.chart5);
            // 显示加载动画
            this.chart5.showLoading(this.loadingOption);
            // console.log(this.queryParams)
            let { data } = await getTokens(query);
            this.chartData = data;

            // 提取日期和计数数据
            const dates = data.map(item => item.date);
            const counts = data.map(item => item.total_tokens);
            const prompt_tokens = data.map(item => item.prompt_tokens);
            const completion_tokens = data.map(item => item.completion_tokens);
            const total_dollar = data.map(item => item.total_dollar);
            const prompt_dollar = data.map(item => item.prompt_dollar);
            const completion_dollar = data.map(item => item.completion_dollar);
            this.option4 = {
                color: ['#3489FF'],
                grid: {
                    left: '5.5%',
                    right: '0%'
                },
                xAxis: [{
                    type: 'category',
                    data: dates, // 设置 x 轴数据
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        fontSize: 13,
                        color: '#999999',
                        margin: 13
                    },
                    splitLine: {
                        lineStyle: {
                            show: true,
                            color: '#DDDDDD'
                        }
                    }
                }],
                yAxis: [{
                    type: 'value',
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        fontSize: 13,
                        color: '#999999',
                        margin: 13
                    },
                    splitLine: {
                        lineStyle: {
                            show: true,
                            color: '#DDDDDD'
                        }
                    }
                }],
                series: [{
                    data: counts, // 设置 y 轴数据
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [{
                                offset: 0,
                                color: '#94cdfc' // 0% 处的颜色
                            }, {
                                offset: 1,
                                color: '#F4F7FF' // 100% 处的颜色
                            }]
                            // global: false // 缺省为 false
                        }
                    },
                    label: {
                        show: true,
                        position: 'top',
                    }
                }],
                tooltip: { // 鼠标悬浮提示框显示 X和Y 轴数据
                    trigger: 'axis',
                    backgroundColor: 'rgba(32, 33, 36,.7)',
                    borderColor: 'rgba(32, 33, 36,0.20)',
                    borderWidth: 1,
                    textStyle: { // 文字提示样式
                        color: '#fff',
                        fontSize: '12'
                    },
                    axisPointer: { // 坐标轴虚线
                        type: 'cross',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    },
                    formatter: function (params) {
                        const index = params[0].dataIndex;
                        return `
                                日期: ${dates[index]}<br/>
                                发-消耗: ${prompt_tokens[index]}<br/>
                                收-消耗: ${completion_tokens[index]}<br/>
                                总消耗: ${counts[index]}
                            `;
                    }
                },
                dataZoom: {
                    type: 'inside'
                }
            };
            this.option5 = {
                color: ['#3489FF'],
                grid: {
                    left: '5.5%',
                    right: '0%'
                },
                xAxis: [{
                    type: 'category',
                    data: dates, // 设置 x 轴数据
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        fontSize: 13,
                        color: '#999999',
                        margin: 13
                    },
                    splitLine: {
                        lineStyle: {
                            show: true,
                            color: '#DDDDDD'
                        }
                    }
                }],
                yAxis: [{
                    type: 'value',
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        fontSize: 13,
                        color: '#999999',
                        margin: 13
                    },
                    splitLine: {
                        lineStyle: {
                            show: true,
                            color: '#DDDDDD'
                        }
                    }
                }],
                series: [{
                    data: total_dollar, // 设置 y 轴数据
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [{
                                offset: 0,
                                color: '#94cdfc' // 0% 处的颜色
                            }, {
                                offset: 1,
                                color: '#F4F7FF' // 100% 处的颜色
                            }]
                            // global: false // 缺省为 false
                        }
                    },
                    label: {
                        show: true,
                        position: 'top',
                    }
                }],
                tooltip: { // 鼠标悬浮提示框显示 X和Y 轴数据
                    trigger: 'axis',
                    backgroundColor: 'rgba(32, 33, 36,.7)',
                    borderColor: 'rgba(32, 33, 36,0.20)',
                    borderWidth: 1,
                    textStyle: { // 文字提示样式
                        color: '#fff',
                        fontSize: '12'
                    },
                    axisPointer: { // 坐标轴虚线
                        type: 'cross',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    },
                    formatter: function (params) {
                        const index = params[0].dataIndex;
                        return `
                                日期: ${dates[index]}<br/>
                                发-消耗: ≈$${prompt_dollar[index]}<br/>
                                收-消耗: ≈$${completion_dollar[index]}<br/>
                                总消耗: ≈$${total_dollar[index]}
                            `;
                    }
                },
                dataZoom: {
                    type: 'inside'
                }
            };
            setTimeout(() => {
                this.initChart4();
                this.chart4.hideLoading();
                this.initChart5();
                this.chart5.hideLoading();
            })
        },

        timeChange() {
            if (this.invalidDateRange) return; // 如果标志位为 true，则退出
            this.queryParams.dateRange.start = this.value1[0];
            this.queryParams.dateRange.end = this.value1[1];


            this.getStatistics();


        },
        getKeyByValue(object, value) {
            return Object.keys(object).find((key) => object[key] === value);
        },

        resetQuery() {
            this.queryParams.language = null;
            this.queryParams.country = null;
            this.queryParams.dateRange.start = null;
            this.queryParams.dateRange.end = null;
            this.queryParams.page = 1;
            this.value1 = "";
            this.str = '近30天'

            this.getStatistics();


        },
        async handleExport() {
            this.loading = true;
            let { data } = await calculateDailySuccessfulPayments(this.queryParams);

            const headers = {
                date: '日期',
                count: '续订人数'
            };
            const transformedData = data.map(item => {
                const newItem = {};
                for (const key in item) {
                    if (headers[key]) {
                        newItem[headers[key]] = item[key];
                    } else {
                        newItem[key] = item[key];
                    }
                }
                return newItem;
            });


            const ws = XLSX.utils.json_to_sheet(transformedData); // 将JSON转换成sheet
            const wb = XLSX.utils.book_new(); // 新建workbook
            XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); // 在workbook中添加新的sheet
            XLSX.writeFile(wb, "MySpreadsheet.xlsx"); // 写文件并触发下载
        },
        async handleExport2() {
            this.loading = true;
            let { data } = await calculateDailySuccessfulRefunds(this.queryParams);

            const headers = {
                date: '日期',
                count: '退款人数'
            };
            const transformedData = data.map(item => {
                const newItem = {};
                for (const key in item) {
                    if (headers[key]) {
                        newItem[headers[key]] = item[key];
                    } else {
                        newItem[key] = item[key];
                    }
                }
                return newItem;
            });


            const ws = XLSX.utils.json_to_sheet(transformedData); // 将JSON转换成sheet
            const wb = XLSX.utils.book_new(); // 新建workbook
            XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); // 在workbook中添加新的sheet
            XLSX.writeFile(wb, "MySpreadsheet.xlsx"); // 写文件并触发下载
        },
        async handleExport3() {
            this.loading = true;
            let { data } = await calculateConversionRate(this.queryParams);

            const headers = {
                date: '日期',
                initialCount: '试用',
                renewalCount: '续费人数',
                conversionRate: '转正率',
            };
            const transformedData = data.map(item => {
                const newItem = {};
                for (const key in item) {
                    if (headers[key]) {
                        newItem[headers[key]] = item[key];
                    } else {
                        newItem[key] = item[key];
                    }
                }
                return newItem;
            });


            const ws = XLSX.utils.json_to_sheet(transformedData); // 将JSON转换成sheet
            const wb = XLSX.utils.book_new(); // 新建workbook
            XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); // 在workbook中添加新的sheet
            XLSX.writeFile(wb, "MySpreadsheet.xlsx"); // 写文件并触发下载
        },
        async handleExport4() {
            this.loading = true;
            let { data } = await calculateDailyDirectPurchases(this.queryParams);

            const headers = {
                date: '日期',
                count: '直接购买人数',
            };
            const transformedData = data.map(item => {
                const newItem = {};
                for (const key in item) {
                    if (headers[key]) {
                        newItem[headers[key]] = item[key];
                    } else {
                        newItem[key] = item[key];
                    }
                }
                return newItem;
            });


            const ws = XLSX.utils.json_to_sheet(transformedData); // 将JSON转换成sheet
            const wb = XLSX.utils.book_new(); // 新建workbook
            XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); // 在workbook中添加新的sheet
            XLSX.writeFile(wb, "MySpreadsheet.xlsx"); // 写文件并触发下载
        },

        initChart1() {
            this.chartContainer1 = this.$echarts.init(document.querySelector('.police-count1'))
            this.chartContainer1.setOption(this.option1)
        },
        initChart2() {
            this.chartContainer2 = this.$echarts.init(document.querySelector('.police-count2'))
            this.chartContainer2.setOption(this.option2)
        },
        initChart3() {
            this.chartContainer3 = this.$echarts.init(document.querySelector('.police-count3'))
            this.chartContainer3.setOption(this.option3)
        },
        initChart4() {
            this.chartContainer4 = this.$echarts.init(document.querySelector('.police-count4'))
            this.chartContainer4.setOption(this.option4)
        },
        initChart5() {
            this.chartContainer5 = this.$echarts.init(document.querySelector('.police-count5'))
            this.chartContainer5.setOption(this.option5)
        },
    },
};
</script>
<style lang="scss" scoped>
.boxs {
    padding: 20px;
}

::v-deep.el-input.is-disabled .el-input__inner {
    color: #333 !important;
}

::v-deep.el-textarea.is-disabled .el-textarea__inner {
    color: #333 !important;
}

::v-deep .el-image {
    margin-right: 8px;
    border-radius: 4px;
}
::v-deep .el-card__body{
    padding: 0;
}
.statistics-container {
    display: flex;
    flex-wrap: wrap;
    /* 自动换行 */
    gap: 10px;
    /* 数据块之间的间距 */
    padding: 10px;
    border: 1px solid #ddd;
    margin-bottom: 20px;
    font-size: 14px;
}

.item {
    background-color: #f9f9f9;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    display: inline-block;
    /* 使得每个元素成为一块 */
    white-space: nowrap;
    /* 防止单个元素中的文本换行 */
}

.police-count1,
.police-count2,
.police-count3,
.police-count4,
.police-count5,
.police-count6,
.police-count7,
.police-count8,
.police-count9,
.police-count10 {
    width: 100%;
    height: 350px;
    color: #000;
}


.loading .loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg) !important;
    }

    100% {
        transform: rotate(360deg);
    }
}

  .el-row {
      margin-bottom: 20px;

      &:last-child {
          margin-bottom: 0;
      }
  }

  .el-col {
      border-radius: 4px;
  }

  .bg-purple-dark {
      background: #99a9bf;
  }

  .bg-purple {
      background: #d3dce6;
  }

  .bg-purple-light {
      background: #e5e9f2;
  }

  .grid-content {
      border-radius: 4px;
      min-height: 36px;
  }

  .row-bg {
      padding: 10px 0;
      background-color: #f9fafc;
  }
  span{
    font-weight: 800;
  }
</style>